<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>V8 | Node.js v6.9.4 Documentation</title>
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:400,700,400italic">
  <link rel="stylesheet" href="assets/style.css">
  <link rel="stylesheet" href="assets/sh.css">
  <link rel="canonical" href="https://nodejs.org/api/v8.html">
</head>
<body class="alt apidoc" id="api-section-v8">
  <div id="content" class="clearfix">
    <div id="column2" class="interior">
      <div id="intro" class="interior">
        <a href="/" title="Go back to the home page">
          Node.js
        </a>
      </div>
      <ul>
<li><a class="nav-documentation" href="documentation.html">About these Docs</a></li>
<li><a class="nav-synopsis" href="synopsis.html">Usage &amp; Example</a></li>
</ul>
<div class="line"></div>

<ul>
<li><a class="nav-assert" href="assert.html">Assertion Testing</a></li>
<li><a class="nav-buffer" href="buffer.html">Buffer</a></li>
<li><a class="nav-addons" href="addons.html">C/C++ Addons</a></li>
<li><a class="nav-child_process" href="child_process.html">Child Processes</a></li>
<li><a class="nav-cluster" href="cluster.html">Cluster</a></li>
<li><a class="nav-cli" href="cli.html">Command Line Options</a></li>
<li><a class="nav-console" href="console.html">Console</a></li>
<li><a class="nav-crypto" href="crypto.html">Crypto</a></li>
<li><a class="nav-debugger" href="debugger.html">Debugger</a></li>
<li><a class="nav-dns" href="dns.html">DNS</a></li>
<li><a class="nav-domain" href="domain.html">Domain</a></li>
<li><a class="nav-errors" href="errors.html">Errors</a></li>
<li><a class="nav-events" href="events.html">Events</a></li>
<li><a class="nav-fs" href="fs.html">File System</a></li>
<li><a class="nav-globals" href="globals.html">Globals</a></li>
<li><a class="nav-http" href="http.html">HTTP</a></li>
<li><a class="nav-https" href="https.html">HTTPS</a></li>
<li><a class="nav-modules" href="modules.html">Modules</a></li>
<li><a class="nav-net" href="net.html">Net</a></li>
<li><a class="nav-os" href="os.html">OS</a></li>
<li><a class="nav-path" href="path.html">Path</a></li>
<li><a class="nav-process" href="process.html">Process</a></li>
<li><a class="nav-punycode" href="punycode.html">Punycode</a></li>
<li><a class="nav-querystring" href="querystring.html">Query Strings</a></li>
<li><a class="nav-readline" href="readline.html">Readline</a></li>
<li><a class="nav-repl" href="repl.html">REPL</a></li>
<li><a class="nav-stream" href="stream.html">Stream</a></li>
<li><a class="nav-string_decoder" href="string_decoder.html">String Decoder</a></li>
<li><a class="nav-timers" href="timers.html">Timers</a></li>
<li><a class="nav-tls" href="tls.html">TLS/SSL</a></li>
<li><a class="nav-tty" href="tty.html">TTY</a></li>
<li><a class="nav-dgram" href="dgram.html">UDP/Datagram</a></li>
<li><a class="nav-url" href="url.html">URL</a></li>
<li><a class="nav-util" href="util.html">Utilities</a></li>
<li><a class="nav-v8 active" href="v8.html">V8</a></li>
<li><a class="nav-vm" href="vm.html">VM</a></li>
<li><a class="nav-zlib" href="zlib.html">ZLIB</a></li>
</ul>
<div class="line"></div>

<ul>
<li><a class="nav-https-github-com-nodejs-node" href="https://github.com/nodejs/node">GitHub Repo &amp; Issue Tracker</a></li>
<li><a class="nav-http-groups-google-com-group-nodejs" href="http://groups.google.com/group/nodejs">Mailing List</a></li>
</ul>

    </div>

    <div id="column1" data-id="v8" class="interior">
      <header>
        <h1>Node.js v6.9.4 Documentation</h1>
        <div id="gtoc">
          <p>
            <a href="index.html" name="toc">Index</a> |
            <a href="all.html">View on single page</a> |
            <a href="v8.json">View as JSON</a>
          </p>
        </div>
        <hr>
      </header>

      <div id="toc">
        <h2>Table of Contents</h2>
        <ul>
<li><span class="stability_undefined"><a href="#v8_v8">V8</a></span><ul>
<li><span class="stability_undefined"><a href="#v8_v8_getheapstatistics">v8.getHeapStatistics()</a></span></li>
<li><span class="stability_undefined"><a href="#v8_v8_getheapspacestatistics">v8.getHeapSpaceStatistics()</a></span></li>
<li><span class="stability_undefined"><a href="#v8_v8_setflagsfromstring_string">v8.setFlagsFromString(string)</a></span></li>
</ul>
</li>
</ul>

      </div>

      <div id="apicontent">
        <h1>V8<span><a class="mark" href="#v8_v8" id="v8_v8">#</a></span></h1>
<p>The <code>v8</code> module exposes APIs that are specific to the version of <a href="https://developers.google.com/v8/">V8</a>
built into the Node.js binary. It can be accessed using:</p>
<pre><code class="lang-js">const v8 = require(&#39;v8&#39;);
</code></pre>
<p><em>Note</em>: The APIs and implementation are subject to change at any time.</p>
<h2>v8.getHeapStatistics()<span><a class="mark" href="#v8_v8_getheapstatistics" id="v8_v8_getheapstatistics">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v1.0.0</span>
</div><p>Returns an object with the following properties:</p>
<ul>
<li><code>total_heap_size</code> <span class="type">&lt;number&gt;</span></li>
<li><code>total_heap_size_executable</code> <span class="type">&lt;number&gt;</span></li>
<li><code>total_physical_size</code> <span class="type">&lt;number&gt;</span></li>
<li><code>total_available_size</code> <span class="type">&lt;number&gt;</span></li>
<li><code>used_heap_size</code> <span class="type">&lt;number&gt;</span></li>
<li><code>heap_size_limit</code> <span class="type">&lt;number&gt;</span></li>
</ul>
<p>For example:</p>
<pre><code class="lang-js">{
  total_heap_size: 7326976,
  total_heap_size_executable: 4194304,
  total_physical_size: 7326976,
  total_available_size: 1152656,
  used_heap_size: 3476208,
  heap_size_limit: 1535115264
}
</code></pre>
<h2>v8.getHeapSpaceStatistics()<span><a class="mark" href="#v8_v8_getheapspacestatistics" id="v8_v8_getheapspacestatistics">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v6.0.0</span>
</div><p>Returns statistics about the V8 heap spaces, i.e. the segments which make up
the V8 heap. Neither the ordering of heap spaces, nor the availability of a
heap space can be guaranteed as the statistics are provided via the V8
<a href="https://v8docs.nodesource.com/node-5.0/d5/dda/classv8_1_1_isolate.html#ac673576f24fdc7a33378f8f57e1d13a4"><code>GetHeapSpaceStatistics</code></a> function and may change from one V8 version to the
next.</p>
<p>The value returned is an array of objects containing the following properties:</p>
<ul>
<li><code>space_name</code> <span class="type">&lt;string&gt;</span></li>
<li><code>space_size</code> <span class="type">&lt;number&gt;</span></li>
<li><code>space_used_size</code> <span class="type">&lt;number&gt;</span></li>
<li><code>space_available_size</code> <span class="type">&lt;number&gt;</span></li>
<li><code>physical_space_size</code> <span class="type">&lt;number&gt;</span></li>
</ul>
<p>For example:</p>
<pre><code class="lang-json">[
  {
    &quot;space_name&quot;: &quot;new_space&quot;,
    &quot;space_size&quot;: 2063872,
    &quot;space_used_size&quot;: 951112,
    &quot;space_available_size&quot;: 80824,
    &quot;physical_space_size&quot;: 2063872
  },
  {
    &quot;space_name&quot;: &quot;old_space&quot;,
    &quot;space_size&quot;: 3090560,
    &quot;space_used_size&quot;: 2493792,
    &quot;space_available_size&quot;: 0,
    &quot;physical_space_size&quot;: 3090560
  },
  {
    &quot;space_name&quot;: &quot;code_space&quot;,
    &quot;space_size&quot;: 1260160,
    &quot;space_used_size&quot;: 644256,
    &quot;space_available_size&quot;: 960,
    &quot;physical_space_size&quot;: 1260160
  },
  {
    &quot;space_name&quot;: &quot;map_space&quot;,
    &quot;space_size&quot;: 1094160,
    &quot;space_used_size&quot;: 201608,
    &quot;space_available_size&quot;: 0,
    &quot;physical_space_size&quot;: 1094160
  },
  {
    &quot;space_name&quot;: &quot;large_object_space&quot;,
    &quot;space_size&quot;: 0,
    &quot;space_used_size&quot;: 0,
    &quot;space_available_size&quot;: 1490980608,
    &quot;physical_space_size&quot;: 0
  }
]
</code></pre>
<h2>v8.setFlagsFromString(string)<span><a class="mark" href="#v8_v8_setflagsfromstring_string" id="v8_v8_setflagsfromstring_string">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v1.0.0</span>
</div><p>The <code>v8.setFlagsFromString()</code> method can be used to programmatically set
V8 command line flags. This method should be used with care. Changing settings
after the VM has started may result in unpredictable behavior, including
crashes and data loss; or it may simply do nothing.</p>
<p>The V8 options available for a version of Node.js may be determined by running
<code>node --v8-options</code>.  An unofficial, community-maintained list of options
and their effects is available <a href="https://github.com/thlorenz/v8-flags/blob/master/flags-0.11.md">here</a>.</p>
<p>Usage:</p>
<pre><code class="lang-js">// Print GC events to stdout for one minute.
const v8 = require(&#39;v8&#39;);
v8.setFlagsFromString(&#39;--trace_gc&#39;);
setTimeout(function() { v8.setFlagsFromString(&#39;--notrace_gc&#39;); }, 60e3);
</code></pre>

      </div>
    </div>
  </div>
  <script src="assets/sh_main.js"></script>
  <script src="assets/sh_javascript.min.js"></script>
  <script>highlight(undefined, undefined, 'pre');</script>
</body>
</html>

